package com.ruoyi.hospital.controller.member;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.member.MemberComment;
import com.ruoyi.hospital.service.member.IMemberCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户评论Controller
 * 
 * @author wendao
 * @date 2024-09-29
 */
@RestController
@RequestMapping("/hospital/comment")
public class MemberCommentController extends BaseController
{
    @Autowired
    private IMemberCommentService memberCommentService;

    /**
     * 查询用户评论列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberComment memberComment)
    {
        startPage();
        List<MemberComment> list = memberCommentService.selectMemberCommentList(memberComment);
        return getDataTable(list);
    }

    /**
     * 导出用户评论列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:comment:export')")
    @Log(title = "用户评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberComment memberComment)
    {
        List<MemberComment> list = memberCommentService.selectMemberCommentList(memberComment);
        ExcelUtil<MemberComment> util = new ExcelUtil<MemberComment>(MemberComment.class);
        util.exportExcel(response, list, "用户评论数据");
    }

    /**
     * 获取用户评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:comment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(memberCommentService.selectMemberCommentById(id));
    }

    /**
     * 新增用户评论
     */
    @PreAuthorize("@ss.hasPermi('hospital:comment:add')")
    @Log(title = "用户评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberComment memberComment)
    {
        return toAjax(memberCommentService.insertMemberComment(memberComment));
    }

    /**
     * 修改用户评论
     */
    @PreAuthorize("@ss.hasPermi('hospital:comment:edit')")
    @Log(title = "用户评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberComment memberComment)
    {
        return toAjax(memberCommentService.updateMemberComment(memberComment));
    }

    /**
     * 删除用户评论
     */
    @PreAuthorize("@ss.hasPermi('hospital:comment:remove')")
    @Log(title = "用户评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(memberCommentService.deleteMemberCommentByIds(ids));
    }
}
